import os
from dotenv import load_dotenv
from fastapi.templating import Jinja2Templates
from fastapi import FastAPI, Request, HTTPException, status, Response
from typing import Dict, List
from models import ChatMessage
import secrets

# 设置模板目录
templates = Jinja2Templates(directory="templates")

# 加载环境变量
load_dotenv()

# 从环境变量中获取用户名和密码
USERNAME = os.getenv("USERNAME")
PASSWORD = os.getenv("PASSWORD")
# 百炼API_KEY
DASHSCOPE_API_KEY = os.getenv("DASHSCOPE_API_KEY")
# 百炼工作空间
DASHSCOPE_WORKSPACE_ID = os.getenv("DASHSCOPE_WORKSPACE_ID")

#Session密钥
SECRET_KEY = os.getenv("SECRET_KEY","my-secret-key")

# 获取当前登录用户
# def get_current_user(request: Request):
#     user = request.session.get('user')
#     if not user:
#         # 用户未登录，抛出异常并重定向到登录页
#         raise HTTPException(
#             status_code=status.HTTP_303_SEE_OTHER,
#             detail="未授权访问: 用户未登录",
#             headers={"Location": "/login"}
#         )
#     return user
